//============================================================================
// Name        : SocketTest.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <stdio.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <string.h>
#include <iostream>
using namespace std;

int main() {
	struct sockaddr_in server_addr;
	server_addr.sin_len = sizeof(struct sockaddr_in);
	server_addr.sin_family = AF_INET;
	server_addr.sin_port = htons(6666);
	server_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
	bzero(&(server_addr.sin_zero), 8);

	int server_socket = socket(AF_INET, SOCK_STREAM, 0);
	if (server_socket == -1) {
		perror("socket error");
		return 1;
	}
	char recv_msg[1024];
	string send_msg("{\"id\":1, \"method\":\"Decode\",\"params\":{\"TimeOut\":10000,\"SaveImg\":true},\"jsonrpc\":\"2.0\"} \r\n");

	if (connect(server_socket, (struct sockaddr *) &server_addr,
			sizeof(struct sockaddr_in)) == 0) {
		if (send(server_socket, send_msg.c_str(), 1024, 0) == -1) {
			perror("send error");
		} else {

			long byte_num = recv(server_socket, recv_msg, 1024, 0);
			cout << "Decode recv:" << recv_msg << endl;

		}

	}


	cout<<"hello.3"<<endl;
	return 0;
}
